//
//  BaseAlert.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/24.
//

#import "BaseAlert.h"
#import "CommonUtil.h"

@interface BaseAlert()
@property (strong, nonatomic) UIButton * bgBtn;
@end

@implementation BaseAlert


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.bgBtn];
        UIWindow *keywin = [self getKeyWindow];
        [keywin addSubview:self];
    }
    return self;
}

- (void)show{
    

}


-(void)dismiss{
    [self removeFromSuperview];
}





#pragma mark -lazy
-(UIButton *)bgBtn{
    if (!_bgBtn) {
        _bgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_bgBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
        _bgBtn.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        _bgBtn.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
    }
    return _bgBtn;
}

-(UIView *)whiteView{
    if (!_whiteView) {
        _whiteView = [[UIView alloc] init];
        _whiteView.backgroundColor = [UIColor whiteColor];
  
        _whiteView.layer.shadowColor = [UIColor blackColor].CGColor;
        _whiteView.layer.shadowRadius= AD(3);
        _whiteView.layer.shadowOpacity = 0.3f;
        _whiteView.layer.shadowOffset = CGSizeMake(0,0);
    }
    return _whiteView;
}

- (void)dealloc{
    NSLog(@"弹框dealloc");
}



- (UIWindow *)getKeyWindow
{
    if (@available(iOS 13.0, *))
    {
        for (UIWindowScene* windowScene in [UIApplication sharedApplication].connectedScenes) {
            if (windowScene.activationState == UISceneActivationStateForegroundActive)
            {
                for (UIWindow *window in windowScene.windows)
                {
                    if (window.isKeyWindow)
                    {
                        return window;
                        break;
                    }
                }
            }
        }
    }
    else
    {
        return [UIApplication sharedApplication].keyWindow;
    }
    return nil;
}

@end
